{template 'common/header'}
<script>
    $(function(){
        $(".freight-change").on('blur',function(){
            var re = /^[0-9]+.?[0-9]*/
            var price = $(this).val();
            var order_goods_id = $(this).attr('order_goods_id');
            if(re.test(price)){
                var url = "{php echo $this->createWebUrl('cashier',array('op' => 'change_log'))}";
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'price' : price, 'type' : 'freight', 'order_goods_id' : order_goods_id},
                    success : function(data){
                        location.reload();
                    }
                });
            }else{
                alert("请输入数字！");
            }
        });
        $(".gen-change").on('blur',function(){
            var re = /^[0-9]+.?[0-9]*/
            var price = $(this).val();
            var order_goods_id = $(this).attr('order_goods_id');
            if(re.test(price)){
                var url = "{php echo $this->createWebUrl('cashier',array('op' => 'change_log'))}";
                $.ajax({
                    type : 'post',
                    url : url,
                    data : {'price' : price, 'type' : 'gen_pay', 'order_goods_id' : order_goods_id},
                    success : function(data){
                        location.reload();
                    }
                });
            }else{
                alert("请输入数字！");
            }
        });
        $("#find").click(function(){
            var key_word = $("#key_word").val();
            location.href="{php echo $this->createWebUrl('cashier',array('op' => 'had_get'))}&key_word="+key_word;
        });
        $(".del").on('click',function(){
            if(confirm("是否确定撤销该收款？")){
                var id = $(this).attr('log-id');
                if(id > 0){
                    var url = "{php echo $this->createWebUrl('cashier',array('op' => 'del_log'))}";
                    $.ajax({
                        type : 'post',
                        url : url,
                        data : {'id' : id},
                        success : function(data){
                            if(data == 111){
                              location.reload();
                            }else{
                                alert(data);
                            }
                        }
                    });
                }
            }
        });
    });
</script>
<ul class="nav nav-tabs">
    <li><a href="{php echo $this->createWebUrl('cashier')}">未收款</a></li>
    <li ><a href="{php echo $this->createWebUrl('cashier', array('slow_pay'=>1))}">月结单</a></li>
    <li class="active"><a href="{php echo $this->createWebUrl('cashier', array('op'=>'had_get'))}">未审核已收款</a></li>
    <li ><a href="{php echo $this->createWebUrl('cashier', array('op'=>'express'))}">服务社</a></li>
    <li ><a href="{php echo $this->createWebUrl('cashier', array('op'=>'express','slow_pay' => 1))}">服务社月结单</a></li>
</ul>
<div>
    <div class="row">
        <div class="col-xs-3">
            <input type="text" placeholder="客户名称/助记码/手机号码" value="{$key_word}" id="key_word" class="form-control" />
        </div>
        <div class="col-xs-3">
            <button class="btn btn-primary" id="find">搜索</button>
        </div>
    </div>
    <br />
    <div>
        <table class="table">
            <tr>
                <th>客户</th>
                <th>订单日期</th>
                <th>商品</th>
                <th>运费</th>
                <th>代付款</th>
                <th>已收运费</th>
                <th>已收代付款</th>
                <th>收款日期</th>
                <th>收款人</th>
                <th>备注</th>
                <th>撤销</th>
            </tr>
            {loop $pay_log $log}
            <tr>
                <td>
                    {if $log['type'] == 2}
                    {$log['server_name']}
                    <p>({$log['name']})</p>
                    {else}
                    {$log['name']}
                    {/if}
                </td>
                <td>
                    {$log['day']}
                    {if $log['o_remark']}
                    <p style="color:red;">{$log['o_remark']}</p>
                    {/if}
                    {if $log['og_remark']}
                    <p style="color:red;">{$log['og_remark']}</p>
                    {/if}
                </td>
                <td>{$log['goods_name']}</td>
                <td>{$log['total_freight']}</td>
                <td>{$log['gen_pay']}</td>
                <td>
                    {if $log['my_freight']}
                    <input type="text" value="{$log['had_freight']}" class="form-control freight-change" order_goods_id="{$log['og_id']}"  />
                    {else}
                    {$log['had_freight']}
                    {/if}
                </td>
                <td>
                    {if $log['my_gen'] }
                    <input type="text" value="{$log['had_gen_pay']}" class="form-control gen-change" order_goods_id="{$log['og_id']}" />
                    {else}
                    {$log['had_gen_pay']}
                    {/if}
                </td>
                <td>{$log['create_time']}</td>
                <td>{$log['user']}</td>
                <td>{$log['had_remark']}</td>
                <td>
                    <button class="btn btn-danger del" log-id="{$log['id']}">撤销</button>
                </td>
            </tr>
            {/loop}
            <tr>
                <td colspan="5"></td>
                <td>总已收运费：{$total_freight}</td>
                <td>总已收代付款：{$total_gen_pay}</td>
                <td>总已收款：{$total}</td>
                <td></td>
            </tr>
        </table>
    </div>
</div>




{template 'common/footer'}